//
// ********************************************************************
// * License and Disclaimer                                           *
// *                                                                  *
// * The  Geant4 software  is  copyright of the Copyright Holders  of *
// * the Geant4 Collaboration.  It is provided  under  the terms  and *
// * conditions of the Geant4 Software License,  included in the file *
// * LICENSE and available at  http://cern.ch/geant4/license .  These *
// * include a list of copyright holders.                             *
// *                                                                  *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work  make  any representation or  warranty, express or implied, *
// * regarding  this  software system or assume any liability for its *
// * use.  Please see the license in the file  LICENSE  and URL above *
// * for the full disclaimer and the limitation of liability.         *
// *                                                                  *
// * This  code  implementation is the result of  the  scientific and *
// * technical work of the GEANT4 collaboration.                      *
// * By using,  copying,  modifying or  distributing the software (or *
// * any work based  on the software)  you  agree  to acknowledge its *
// * use  in  resulting  scientific  publications,  and indicate your *
// * acceptance of all terms of the Geant4 Software license.          *
// ********************************************************************

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

#include "DetectorMessenger.hh"

#include "DetectorConstruction.hh"
#include "G4UIcmdWithADouble.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIdirectory.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorMessenger::DetectorMessenger(DetectorConstruction* h) : fDetector(h)
{
    fDetDir = new G4UIdirectory("/testem/det/");
    fDetDir->SetGuidance("commands to define detector");

    ///=========================
    fAbsMaterCmd = new G4UIcmdWithAString("/testem/det/AbsorberMaterial", this);
    fAbsMaterCmd->SetGuidance("Select Material of the Absorber");
    fAbsMaterCmd->SetParameterName("AbsorberMaterial", false);
    fAbsMaterCmd->AvailableForStates(G4State_PreInit, G4State_Idle);

    ///=========================
    fPhaZCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/PhantomZ", this);
    fPhaZCmd->SetGuidance("Set Length of Phantom");
    fPhaZCmd->SetParameterName("PhantomZ", false);
    fPhaZCmd->SetUnitCategory("Length");
    fPhaZCmd->AvailableForStates(G4State_PreInit);

    ///=========================
    fVerbCmd = new G4UIcmdWithAnInteger("/testem/det/verbose", this);
    fVerbCmd->SetGuidance("Set verbose for ");
    fVerbCmd->SetParameterName("verb", false);
    fVerbCmd->AvailableForStates(G4State_PreInit, G4State_Idle);

    ///2022.10.18
    ///=========================
    fPhaXYCmd = new G4UIcmdWithADoubleAndUnit("/testem/det/PhantomXY", this);
    fPhaXYCmd->SetGuidance("Set Width of Phantom");
    fPhaXYCmd->SetParameterName("PhantomXY", false);
    fPhaXYCmd->SetUnitCategory("Length");
    fPhaXYCmd->AvailableForStates(G4State_PreInit);

    ///=========================
    fFactorCmd = new G4UIcmdWithADouble("/testem/det/Factor", this);
    fFactorCmd->SetGuidance("Set Length Factor of World over Phantom");
    fFactorCmd->SetParameterName("Factor", false);
    fFactorCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

DetectorMessenger::~DetectorMessenger()
{
    delete fAbsMaterCmd;
    delete fPhaZCmd;

    delete fVerbCmd;
    delete fDetDir;
    delete fPhaXYCmd;
    delete fFactorCmd;
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

void DetectorMessenger::SetNewValue(G4UIcommand* command, G4String newValue)
{
    if (command == fAbsMaterCmd)
    {
        fDetector->SetNewMaterial(newValue);
    }

    if (command == fPhaZCmd)
    {
        fDetector->SetPhantomZ(fPhaZCmd->GetNewDoubleValue(newValue));
    }

    if (command == fVerbCmd)
    {
        fDetector->SetVerbose(fVerbCmd->GetNewIntValue(newValue));
    }

    if (command == fPhaXYCmd)
    {
        fDetector->SetPhantomXY(fPhaXYCmd->GetNewDoubleValue(newValue));
    }

    if (command == fFactorCmd)
    {
        fDetector->SetFactor(fFactorCmd->GetNewDoubleValue(newValue));
    }
}

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......